using Sustainalytics.ESGRatings.BusinessLogic.Computing.Exceptions;
using Sustainalytics.ESGRatings.BusinessLogic.Computing.Utils;
using Sustainalytics.ESGRatings.Computing.Entities;
using System;
using System.Collections.Generic;

namespace Sustainalytics.ESGRatings.BusinessLogic.Computing
{


    public abstract class IndicatorConfigurationFactory
    {
        public abstract IndicatorsConfiguration.IndicatorsConfigurationBuilder GetBuilder();
    }

    public class ESGIndicatorConfigurationFactory : IndicatorConfigurationFactory
    {

        public override IndicatorsConfiguration.IndicatorsConfigurationBuilder GetBuilder()
        {
         
            var builder = new IndicatorsConfiguration.IndicatorsConfigurationBuilder("E", "S", "G");
            return builder;
        }
    }


    public class GovernanceIndicatorConfigurationFactory : IndicatorConfigurationFactory
    {
        public override IndicatorsConfiguration.IndicatorsConfigurationBuilder GetBuilder()
        {
            var builder = new IndicatorsConfiguration.IndicatorsConfigurationBuilder("E", "S", "G");
            return builder;
        }
    }


    public static class IndicatorConfigurationExtention
    {
        public static IndicatorsConfiguration GetConfiguration(this IndicatorsConfiguration.IndicatorsConfigurationBuilder builder,ICollection<IndicatorTemplate> indicators)
        {
            if (indicators.IsNullOrEmpty())
                throw new ArgumentNullException("indicators");

            foreach (var indicator in indicators)
            {
                if (!builder.GetAvailableThemes().Contains(indicator.Theme))
                    throw new UnknownTheme { ThemeCode = indicator.Theme };

                builder.AddIndicator(indicator.Code, indicator.Theme, indicator.Cluster);
            }
            return builder.Build();
        }
    }
}